<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体检项目</title>
</head>
<body>
	<script type="text/javascript">
		$(function(){
			
			//项目信息
			$("#healproject-dg").datagrid({	
				url:'init-healproject',
	 		    columns:[[
	 		    	   {field:'prolid',title:'',width:40,checkbox:true},
	 		    	   {field:'project_no',title:'编号',width:160},
	 		    	   {field:'project_name',title:'项目名称',width:350},
	 				   {field:'project_price',title:'项目价格',width:220},
					   {field:'section_name',title:'项目科室',width:280}

	 		    ]]
			});
			
			//新增项目
			$("#add-healproject").click(function(){
				$("#add-healpro-win").window("open");
			});
			
			
			//项目新增的按钮
			$("#add-project").click(function(){
				$('#pro-for').form({
				    url:'add-healthproject',
				    onSubmit: function(){
				    	// 执行验证    
				        var c=$('#pro-for').form("validate");
				        // return false 取消表单提交;
				        return c;
				    },
				    success:function(data){
				    	$("#healproject-dg").datagrid('reload');//新增之后会刷新
				    	$('#pro-for').form("clear");//清空文本
				    	$("#add-healpro-win").window("close");
				    	$("#healproject-dg").datagrid('clearChecked');
				    	$.messager.show({
                            title:'提示信息' , 
                            msg:'体检项目新增成功!'
                        });
				    }
				}).submit();
			});
			
			
			
			//修改项目
			$("#edit-healptoject").click(function(){
				//获取的项
				var rows =$("#healproject-dg").datagrid('getSelected');
				if(rows == null){
					$.messager.confirm('Confirm', 
							'未选中行，请选择一行', 
							function(r){
					});
				}else{
					$("#deit-healpro-win").window("open");
					$("#healproject-dg").datagrid('clearChecked');
					$("#pname").textbox('setValue',rows['project_name']);
					$("#pprice").textbox('setValue',rows['project_price']);
					$("#pno").textbox('setValue',rows['project_no']);
					$("#pno").textbox('textbox').attr('readonly',true);  
				}
				
								
			});
			
			$("#update-project").click(function(){
				$('#updatepro-for').form({
				    url:'update-healthproject',
				    onSubmit: function(){
				    	  // 执行验证    
				        var c=$('#updatepro-for').form("validate");
				        // return false 取消表单提交;
				        return c;
				    },
				    success:function(data){
				    	$("#healproject-dg").datagrid('reload');//新增之后会刷新
				    	$('#updatepro-for').form("clear");//清空文本
				    	$("#deit-healpro-win").window("close");
				    	$("#healproject-dg").datagrid('clearChecked');
				    	$.messager.show({
                            title:'提示信息' , 
                            msg:'体检项目修改成功!,请及时查看结果'
                        });
				    }
				}).submit();
			});
			
			
			//初始化科室下拉表的数据
			$('#sections').combobox({   
	         	url:'init-hospsection',//数据源
	         	valueField: 'section_id',//实体类名字---主键id
		        textField: 'section_name',//需要显示在下拉框的实际内容
		        editable:false,
	            panelHeight:'auto',//高度根据内容自动定
	            onLoadSuccess: function () {  //加载完成后,设置选中第一项
	                    var val = $(this).combobox("getData");
	                    for (var item in val[0]) {
	                        if (item == "section_id") {
	                        	//初始化数据默认选中第一个
	                            $(this).combobox("select", val[0][item]);
	                        }
	                    }
	             }
 
	        });

		});
		
		
		//验证
		$.extend($.fn.textbox.defaults.rules, {
				proname: {
			        validator: function(value, param) {
			            var reg = /^[\u4e00-\u9fa5]+$/i;
			            return reg.test(value);
			        },
			        message: "项目名称请输入中文"
			    },
			    pprice:{
			    	validator: function(value, param) {
			            var addressreg = /^[0-9]*$/;
			            return addressreg.test(value);
			        },
			        message: "请输入正确的数字"
			    }
			    
	   });//自定义验证

	
	</script>
	<fieldset class="login-record" style="border:1px solid #A6A6A6;width:1050px;margin:20px auto;border-radius:6px;">
		<legend style="font-size:16px;">化验项目信息</legend>
		<div class="healproject-tab" style="margin-top: 10px;">
			<table id="healproject-dg" class="logininform-table easyui-datagrid" style="height:400px;" 
			data-options="toolbar:'#healproject-tb',fitColumns:false,singleSelect:false">
			</table>
		</div>
	</fieldset>
	
	
	<!-- 工具栏 -->
	<div id="healproject-tb">
		<a href="#" id="add-healproject" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">新增项目</a>
		<a href="#" id="edit-healptoject" class="easyui-linkbutton" data-options="iconCls:'icon-help'">修改项目</a>	
	</div>
	
	<!-- 新增和修改项目 的窗口 -->
	<div id="add-healpro-win" class="easyui-window" title="新增体检项目" style="width:300px;height:230px"
		    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		 <div style="width:250px;height:180px;margin: 0px auto;text-align: center;">
			 <form method="Post" id="pro-for">
			 	<p><input id="addname" class="easyui-textbox" name="projectName" data-options="label:'项目名称',required:true,validType:['proname']" style="width:200px;height:30px;"></p>
			 	<p><input id="addprice" class="easyui-textbox" name="projectPrice" data-options="label:'项目价格',required:true,validType:['pprice']"  style="width:200px;height:30px;"></p>
			 	<p>
					<select id="sections" class="easyui-combobox" name="sectionId" data-options="label:'所属科室',height:30" style="width:200px">
					</select>				
			 	</p>
			 	<p>
			 	<a id="add-project" iconCls="icon-ok" class="easyui-linkbutton">提交</a></p>
			    <p>
			 </form>  
		 </div> 
	</div> 
	<div id="deit-healpro-win" class="easyui-window" title="修改体检项目" style="width:300px;height:230px"
		    data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		 <div style="width:250px;height:180px;margin: 0px auto;text-align: center;">
			 <form method="Post" id="updatepro-for">
			 	<p><input id="pname" class="easyui-textbox" name="projectName" data-options="label:'项目名称'" style="width:200px;height:30px;"></p>
			 	<p><input id="pprice" class="easyui-textbox" name="projectPrice" data-options="label:'项目价格'"  style="width:200px;height:30px;"></p>
			 	<p>
			 	<input id="pno" class="easyui-textbox" name="projectNo" data-options="label:'项目编号'" style="width:200px;height:30px;"></p>
			 	<a id="update-project" iconCls="icon-ok" class="easyui-linkbutton">提交</a></p>
			    <p>
			 </form>  
		 </div> 
	</div> 
</body>
</html>